<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>清理本地存储</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }
        .container {
            background: rgba(255, 255, 255, 0.95);
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        button {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            margin: 10px;
            transition: transform 0.2s;
        }
        button:hover {
            transform: translateY(-2px);
        }
        .info {
            background: #f0f9ff;
            border: 1px solid #bae6fd;
            padding: 15px;
            border-radius: 8px;
            margin: 20px 0;
        }
        .success {
            background: #f0fdf4;
            border: 1px solid #bbf7d0;
            color: #059669;
        }
        pre {
            background: #f8fafc;
            padding: 15px;
            border-radius: 8px;
            overflow-x: auto;
            border: 1px solid #e2e8f0;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🔧 本地存储管理工具</h1>
        
        <div class="info">
            <h3>📋 当前存储状态</h3>
            <div id="storageStatus">检查中...</div>
        </div>

        <div style="text-align: center;">
            <button onclick="clearStorage()">🗑️ 清理所有存储</button>
            <button onclick="checkStorage()">🔍 检查存储状态</button>
            <button onclick="showLoginData()">👀 显示登录数据</button>
        </div>

        <div id="result" style="margin-top: 20px;"></div>
    </div>

    <script>
        function checkStorage() {
            const token = localStorage.getItem('token');
            const userInfo = localStorage.getItem('userInfo');
            const loginForm = localStorage.getItem('loginForm');
            
            let status = '<h4>🔍 存储项检查:</h4>';
            status += `<p><strong>Token:</strong> ${token ? '✅ 存在' : '❌ 不存在'}</p>`;
            status += `<p><strong>用户信息:</strong> ${userInfo ? '✅ 存在' : '❌ 不存在'}</p>`;
            status += `<p><strong>记住登录:</strong> ${loginForm ? '✅ 存在' : '❌ 不存在'}</p>`;
            
            document.getElementById('storageStatus').innerHTML = status;
        }

        function showLoginData() {
            const userInfo = localStorage.getItem('userInfo');
            const token = localStorage.getItem('token');
            
            let result = '<h4>📊 登录数据详情:</h4>';
            
            if (userInfo) {
                try {
                    const parsed = JSON.parse(userInfo);
                    result += '<p><strong>用户信息:</strong></p>';
                    result += `<pre>${JSON.stringify(parsed, null, 2)}</pre>`;
                } catch (e) {
                    result += '<p style="color: red;">用户信息格式错误</p>';
                }
            }
            
            if (token) {
                result += `<p><strong>Token:</strong> ${token.substring(0, 50)}...</p>`;
            }
            
            document.getElementById('result').innerHTML = result;
        }

        function clearStorage() {
            try {
                localStorage.removeItem('token');
                localStorage.removeItem('userInfo');
                localStorage.removeItem('loginForm');
                
                // 清理其他可能的应用数据
                const keysToRemove = [];
                for (let i = 0; i < localStorage.length; i++) {
                    const key = localStorage.key(i);
                    if (key && (key.startsWith('eval_') || key.includes('user') || key.includes('auth'))) {
                        keysToRemove.push(key);
                    }
                }
                
                keysToRemove.forEach(key => localStorage.removeItem(key));
                
                document.getElementById('result').innerHTML = `
                    <div class="success">
                        <h4>✅ 清理完成!</h4>
                        <p>已清理以下存储项:</p>
                        <ul>
                            <li>token</li>
                            <li>userInfo</li>
                            <li>loginForm</li>
                            <li>其他相关数据 (${keysToRemove.length} 项)</li>
                        </ul>
                        <p><strong>🎯 现在可以重新访问系统，应该会正确重定向到登录页！</strong></p>
                    </div>
                `;
                
                checkStorage();
                
                // 3秒后提示重新打开应用
                setTimeout(() => {
                    if (confirm('存储已清理完成！是否现在打开测评系统？')) {
                        window.open('http://localhost:5173', '_blank');
                    }
                }, 1000);
                
            } catch (error) {
                document.getElementById('result').innerHTML = `
                    <div style="color: red;">
                        <h4>❌ 清理失败</h4>
                        <p>错误: ${error.message}</p>
                    </div>
                `;
            }
        }

        // 页面加载时自动检查
        window.onload = function() {
            checkStorage();
        };
    </script>
</body>
</html>